<template>
  <div class="echarts">
    <div ref="echartDivRef" :style="{ width, height }"></div>
  </div>
</template>

<script setup lang="ts">
import { EChartsOption } from 'echarts'
import { onMounted, ref, watchEffect, defineProps, withDefaults } from 'vue'
import useEcharts from '../hooks/useEcharts'
const echartDivRef = ref<HTMLElement>()

const props = withDefaults(
  defineProps<{
    options: EChartsOption
    width?: string
    height?: string
  }>(),
  {
    width: '100%',
    height: '380px'
  }
)
onMounted(() => {
  const { setOptions } = useEcharts(echartDivRef.value!)

  watchEffect(() => setOptions(props.options))
})
</script>

<style scoped></style>
